package fr.uniscol.dao.mapper;

import fr.uniscol.model.Classe;
import fr.uniscol.model.Eleve;
import fr.uniscol.model.MEF;
import fr.uniscol.model.Periode;
import fr.uniscol.model.Scolarite;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.GregorianCalendar;
import org.springframework.jdbc.core.RowMapper;

public class ScolariteRowMapper implements RowMapper<Scolarite> {

	@Override
	public Scolarite mapRow(ResultSet rs, int rowNum) throws SQLException {
		
		Scolarite sco = new Scolarite();
        sco.setId(rs.getLong("SCOLARITEID"));
		Eleve el = new Eleve();
		el.setId(rs.getInt("ELEVEID"));
		sco.setEleve(el);
		
		sco.setClasse(new Classe());
		sco.getClasse().setId(rs.getInt("STRUCTUREID"));
		sco.getClasse().setLibelle(rs.getString("LIBELLE"));
		
		sco.setMef(new MEF());
		sco.getMef().setId(rs.getInt("MEFID"));
        sco.getMef().setLibelleLong(rs.getString("LIBELLE_LONG"));
		
		//sco.setActuelle(rs.getInt("ACTUELLE") == 1);
		
        sco.setPeriode(new Periode());
        sco.getPeriode().setDebut(new GregorianCalendar());
        sco.getPeriode().getDebut().setTime(new Date(rs.getDate("DEBUT").getTime()));
        
        if(rs.getString("FIN") != null){
            sco.getPeriode().setFin(new GregorianCalendar());
            sco.getPeriode().getFin().setTime(new Date(rs.getDate("FIN").getTime()));
        }
        
		return sco;
	}
}
